﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
#if !NETCOREAPP
using System.Web;
using System.Web.Mvc;
using System.Web.WebPages;
    using System.Web.Mvc.Html;

#endif

#if NETCOREAPP
using Microsoft.AspNetCore.Mvc.Rendering;
using Kugar.Core.Web;
#endif
using Kugar.Core.ExtMethod;
using Kugar.MVC.MobileUI.WeUI.Helpers;

namespace Kugar.MVC.MobileUI.WeUI.PageControls.PageForm
{
    public class PageForm_Switch:PageForm_FieldBase
    {
        private string _value;
        private bool _checked = false;

        public PageForm_Switch(ViewContext viewContext) : base(viewContext)
        {
            this.Css("weui-cell_switch");
        }

        

        public PageForm_Switch Value(string value)
        {
            _value = value;

            return this;
        }

        public PageForm_Switch Checked(bool isChecked)
        {
            _checked = isChecked;

            return this;
        }

        protected override void RenderHeader()
        {
            
        }

        protected override void RenderBody()
        {
            ViewContext.Writer.WriteLine(_label);
        }

        protected override void RenderFooter()
        {
            /*
              <label for="switchCP" class="weui-switch-cp">
               <input id="switchCP" class="weui-switch-cp__input" type="checkbox" checked="checked">
               <div class="weui-switch-cp__box"></div>
               </label>
             */

            var id = "sb" + WeUI.NextControlID();

            ViewContext.Writer.WriteLine($"<label for=\"{id}\" class=\"weui-switch-cp\">");

            ViewContext.Writer.WriteLine($"<input id=\"{id}\" name=\"{_name}\" class=\"weui-switch-cp__input\" value=\"{_value}\" type=\"checkbox\" {_checked.If("checked=\"checked\"")} />");

            ViewContext.Writer.WriteLine("<div class=\"weui-switch-cp__box\"></div>");

            ViewContext.Writer.WriteLine("</label>");

            base.RenderFooter();


        }
    }
}